#!/usr/bin/sh

modprobe micom

if [ -e /var/etc/.firstboot ]; then
   rm /var/etc/.firstboot
   sleep 1
   echo "WAIT 3 min"
   touch /dev/.devfsd
    mkdir /dev/dbox
    mkdir /dev/input
    mknod /dev/dbox/vfd c 147 0
    mknod /dev/dbox/avs0 c 10 221
    mknod /dev/input/uinput c 10 223
    echo "WAIT 3 min" > /dev/dbox/vfd
fi

if [ -e /etc/init.d/mountvirtfs ]; then
   /etc/init.d/mountvirtfs start
fi

if [ -e /etc/init.d/portmap ]; then
   /etc/init.d/portmap start
fi

modprobe e2_proc

if [ ! -e /var/etc/.firstboot ]; then
   echo "LOADING MODULES" > /dev/dbox/vfd
   echo "LOADING MODULES"   

   echo "init AVS"
   modprobe avs type=stv6418

   echo "init stmfb"
   modprobe stmcore-display-stx7109c3
   tvmode
   modprobe stmfb display0=720x576-32@50:12m:0:pal:cvbs

   echo "load a/v firmware"
   /usr/bin/ustslave /dev/st231-1 /boot/audio.elf
   /usr/bin/ustslave /dev/st231-0 /boot/video.elf

   echo "init embx"
   modprobe embxshell
   modprobe embxmailbox mailbox0=0xb9211000:136:set2 mailbox1=0xb9212000:0 ;
   modprobe embxshm mailbox0=shm:0:7:0x60000000:0:256:256:0:512:0xa4000000:0x10000000 ;
   modprobe mme_host transport0=shm

   echo "init player"
   modprobe mmelog
   modprobe mpeg2hw mmeName=MPEG2_TRANSFORMER1;
   modprobe ksound
   modprobe p2div64
   modprobe stm_v4l2
   modprobe pseudocard
   modprobe fe-core
   modprobe starci
   modprobe pti
   modprobe stmsysfs
   modprobe stm_monitor
   modprobe stmdvb
   
   modprobe player2
   modprobe sth264pp
   modprobe stmalloc
   modprobe platform
   modprobe silencegen
   modprobe rmu
   modprobe ipbox_fan
fi

showiframe -p /usr/share/bootlogo.mvi &
stfbcontrol a 0

if [ ! -e /var/etc/.firstboot ]; then
   echo "enigma2" > /dev/dbox/vfd
   echo "LOADING e2"

if [ -e /etc/init.d/mountall ]; then
   /etc/init.d/mountall start
fi

if [ -e /etc/init.d/vsftpd ]; then
   /etc/init.d/vsftpd start
fi
   /usr/sbin/inetd
   mkdir -p /var/run/lirc
   /usr/bin/lircd

   modprobe simu_button
   /usr/bin/evremote2 &

   stfbcontrol a 255
   until false
   do
      echo "starting e2->"
      /usr/bin/enigma2
      rtv=$?
      echo "e2 ended <- RTV: " $rtv
      case "$rtv" in
		0) echo "0"
		   echo "E2 ERROR"
    		   init 6;;
		1) echo "1"
		   echo "SHUTDOWN"
		   echo "SHUTDOWN" > /dev/dbox/vfd
		   init 0;;
		2) echo "2"
		   echo "REBOOT"
		   init 6;;
		3) echo "3"
		   echo "E2 RESTART"
		   showiframe -p /usr/share/bootlogo.mvi &
		   echo "0" > /proc/progress;;
		*) echo "*"
		   echo "ERROR"
		   showiframe -p /usr/share/bootlogo.mvi &
		   echo "0" > /proc/progress;;
     esac
   done 
fi
